********Figure D.2 - Indonesia********


*Load data
cd "$reploc/data/created_data"
use indo_full, clear


*Do these results for primary sample
sort pidlink ifls
foreach var of varlist rbuc_garefined rbuc grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if ifls==5 & pidlink==pidlink[_n-1]
} 

egen coh_prov_clust=group(biryear_impl birprov_impl)

gen primarysample1=0
replace primarysample1=1 if rbuc_garefineddif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  biryear_impl>=1961 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pidlink)

drop if ifls==.
keep if panel==1
keep if primarysample==1


local usei grbr
local rhsvaruse _lam0co3
local measu Avg SD


keep rbuc*  gambleaverse ifls pidlink inflation imp_age panel biryear_impl grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? birprov_impl

reshape wide rbuc*  gambleaverse inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co?, i(pidlink) j(ifls)

local varlist1 rbuc rbucB rbuc_nga rbuc_garefined rbucgaref1a rbucgaref2a rbucgaref3a rbucgaref4a gambleaverse inflation grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co2 grbrprovSD_lam0co2 grbrprovAvg_lam0co3 grbrprovSD_lam0co3 

foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'5-`var'4
}


local ytit "{&Delta} Growth Standard Deviation"
local xtit xtitle("{&Delta} Growth Mean")
local tit title("Relationship between average growth and volatility of growth")


twoway scatter `usei'provSD`rhsvaruse'dif `usei'provAvg`rhsvaruse'dif, ///
`xtit' ytitle(" ")  ///
subtitle(`ytit', position(11) justification(left) size(medsmall)) ///
yscale(titlegap(*5)) yline(0, lpattern(dash) lwidth(thin)) xline(0, lpattern(dash) lwidth(thin)) msize(vsmall) ///
yscale(range(-0.5 4)) xscale(range(-0.25 2.5)) xlabel(-0.25(0.25)2.5) ylabel(-0.5(0.5)4) graphregion(fcolor(white))

cd "$reploc/results"
graph export FigureD2Indonesia.eps, replace
